package com.example.tests;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ContactModificationTests extends TestBase {
	Random rnd = new Random();
	
	public static String[] MONTHS = new String[]{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
	
	@DataProvider(name = "modifyRandomContact")
	public Iterator<Object[]> modifyRandomContacts() {
		Set<ContactObject> contacts = app.getContactHelper().getContacts();
		ContactObject anyContact= contacts.iterator().next();

		List<Object[]> list = new ArrayList<Object[]>();
		ContactObject newContact = new ContactObject()
				.setFirstName("firstname"+rnd.nextInt())
				.setLastName("lastname"+rnd.nextInt())
				.setAddress("address"+rnd.nextInt())
				.setTelHome("telhome"+rnd.nextInt())
				.setTelMobile("telmobile"+rnd.nextInt())
				.setTelWork("telwork"+rnd.nextInt())
				.setBirthDay("" + generateRandomNumberBetween(1,30))
				.setBirthMonth(MONTHS[generateRandomNumberBetween(1, 12)])
				.setBirthYear("" + generateRandomNumberBetween(1950, 2013))
				.setGroup("[none]")
				.setEmail("email"+rnd.nextInt())
				.setEmail2("email2"+rnd.nextInt())
				.setAddress2("address2"+rnd.nextInt())
				.setPhone2("phone2"+rnd.nextInt());
		
		list.add(new Object[]{anyContact, newContact});
			return list.iterator();
	}

	@Test(dataProvider = "modifyRandomContact")
	public void testValidContactCanBeModificated(ContactObject anyContact, ContactObject newContact) throws Exception {
		
		Set<ContactObject> oldList = app.getContactHelper().getContacts();
		app.getContactHelper().modifyContact(anyContact, newContact);
		Set<ContactObject> newList = app.getContactHelper().getContacts();
		
		verifyContactModificated (oldList, anyContact, newContact, newList);
		
	}
}
